home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / daemons / ipServer / sockInt.h < prev    next >
Encoding:
C/C++ Source or Header  |  1989-08-16  |  7.4 KB  |  210 lines

  1. /*
  2.  * sockInt.h --
  3.  *
  4.  *    Internal declarations of the socket-related routines.
  5.  *    The data structures defined in this filed are used to manage
  6.  *    sockets.
  7.  *
  8.  * Copyright 1987 Regents of the University of California
  9.  * All rights reserved.
  10.  * Permission to use, copy, modify, and distribute this
  11.  * software and its documentation for any purpose and without
  12.  * fee is hereby granted, provided that the above copyright
  13.  * notice appear in all copies.  The University of California
  14.  * makes no representations about the suitability of this
  15.  * software for any purpose.  It is provided "as is" without
  16.  * express or implied warranty.
  17.  *
  18.  *
  19.  * $Header: /sprite/src/daemons/ipServer/RCS/sockInt.h,v 1.6 89/08/15 19:55:38 rab Exp $ SPRITE (Berkeley)
  20.  */
  21.  
  22. #ifndef _IPS_SOCKINT
  23. #define _IPS_SOCKINT
  24.  
  25. #include "sprite.h"
  26. #include "dev/net.h"
  27. #include "netInet.h"
  28. #include "fs.h"
  29. #include "list.h"
  30. #include "proc.h"
  31.  
  32. #ifdef KERNEL
  33. #include "../fs/fsInt.h"
  34. #include "../fs/fsSocket.h"
  35. #endif
  36.  
  37. /*
  38.  * Sock_State defines the various states that a socket can be in at
  39.  * any one moment.
  40.  */
  41. typedef enum {
  42.     UNUSED,        /* Not in use. */
  43.     CREATED,        /* The socket has been created by opening the
  44.              * socket pseudo-device. */
  45.     HAVE_LOCAL_ADDR,    /* A bind operation has been performed. */
  46.     READY,        /* The socket can send and receive datagrams
  47.              * (datagram only). */
  48.     LISTENING,        /* A stream socket is waiting for connection
  49.              * requests from remote hosts. */
  50.     CONNECTING,        /* A stream socket trying to connect to a remote host.*/
  51.     CONNECTED,        /* Stream socket: the connection attempt succeeded.
  52.                  * Datagram socket: the local and remote addresses
  53.              * have been defined. */
  54.     DISCONNECTING,    /* In the process of disconnecting from a remote host */
  55.     DISCONNECTED,    /* The connection has been closed. */
  56. } Sock_State;
  57.  
  58.  
  59. /*
  60.  * There are two buffer queues for a socket. Data in the queue are
  61.  * held in a linked list.
  62.  */
  63. typedef struct {
  64.     List_Links        links;        /* List of Sock_BufDataInfo items. */
  65.     int            size;        /* # of bytes in the bufffer. */
  66.     int            maxSize;    /* Max. # of bytes allowed. */
  67. } Sock_BufInfo;
  68.  
  69.  
  70. /*
  71.  * Each data buffer in a socket buffer queue is described by this structure.
  72.  */
  73.  
  74. typedef struct {
  75.     List_Links    links;            /* All data are linked together */
  76.     Net_InetSocketAddr    address;    /* For reads, who sent the packet. */
  77.     int        len;            /* Number of bytes stored. */
  78.     Address    bufPtr;            /* Ptr to the data buffer. */
  79.     Address    base;            /* Base address of the Mem_Alloc'd
  80.                      * memory used for bufPtr. This is
  81.                      * the address given to Mem_Free when
  82.                      * info is no longer needed. */
  83. } Sock_BufDataInfo;
  84.  
  85. /*
  86.  * Information about the peudo-device request buffer associated with
  87.  * each socket.  This is set up and used when the pseudo-device connection
  88.  * is just being created.  It is passed to the Sock_Open routine, and the
  89.  * location of the request buffer is used for cleanup and for error checking.
  90.  */
  91.  
  92. typedef struct SockPdevState {
  93.     int protoIndex;        /* Type for Sock_SharedInfo */
  94.     int reqBufSize;        /* Size of the request buffer */
  95.     char *requestBuf;        /* The request buffer itself */
  96. } SockPdevState;
  97.  
  98. /*
  99.  * Information about a socket that is shared among processes using the socket.
  100.  *  1) current state of use, protocol type.
  101.  *  2) pointer to protocol-dependent information.
  102.  *  3) queues that hold data to be sent to another socket
  103.  *     and data that has been received from another socket.
  104.  *  4) info about the local and remote addresses assigned to this socket.
  105.  *
  106.  */
  107. typedef struct Sock_SharedInfo {
  108.     List_Links        protoLinks;    /* Links to others of same protocol. */
  109.     int            protoIndex;    /* One of RAW_PROTO_INDEX,
  110.                      * UDP_PROTO_INDEX, TCP_PROTO_INDEX. */
  111.     int            protocol;    /* For raw sockets: the IP protocol #
  112.                      * that must be present in incoming
  113.                      * packet in order to be received;
  114.                      * protocol # used in IP header on
  115.                      * output. */
  116.     ClientData        protoData;    /* Protocol-specific information. */
  117.     int            reqBufSize;    /* Size of the pdev request buffer */
  118.     char            *requestBuf;    /* The pdev request buffer.  Packet
  119.                      * data is put here by the kernel, and
  120.                      * we format packets in place (without
  121.                      * copies) before outputing to the net*/
  122.     Sock_State        state;        /* Defined above. */
  123.     int            options;    /* Manipulated via IOC_NET_GET_OPTION/
  124.                      * SET_OPTION in <dev/net.h>. */
  125.     Ioc_Owner        owner;        /* Current owner (process or family). */
  126.     int            flags;        /* Defined below. */
  127.     int            clientCount;    /* # of users using this socket. */
  128.     ReturnStatus    error;        /* Asynchronous error status from
  129.                      * ICMP or from the protocol-dependent
  130.                      * layer. */
  131.     Sock_BufInfo    recvBuf;    /* Data from the network. */
  132.     Sock_BufInfo    sendBuf;    /* Data to be sent out. */
  133.  
  134.     Net_InetSocketAddr    local;        /* Address for this host. */
  135.     Net_InetSocketAddr    remote;        /* Address for remote host. */
  136.  
  137.     Net_InetSocketAddr    sentTo;        /* Destination of the most-recently
  138.                      * sent packet (only if not connected.)
  139.                      */
  140.     int            linger;        /* # of seconds to wait upon closing. */
  141.     struct Sock_SharedInfo *parentPtr;    /* Used to wakeup a socket waiting to
  142.                      * accept a new connection. */
  143.     List_Links        clientList;    /* List of clients using this socket.
  144.                      * Used to notify when the select state
  145.                      * changes. */
  146.     Boolean        justEstablished; /* Used by a connection-based
  147.                      * protocol's select routine to notify
  148.                      * a waiter that the connection has
  149.                      * just become established. */
  150. } Sock_SharedInfo;
  151.  
  152. /*
  153.  * Sock_SharedInfo flags:
  154.  *    SOCK_STOP_RECV        - don't accept any more data.
  155.  *    SOCK_STOP_SEND        - can't send data any more.
  156.  *    SOCK_URGENT_DATA_NEXT    - urgent data is at the next logical byte
  157.  *                  in the receive buffer.
  158.  *    SOCK_RAW_HAVE_LOCAL_ADDR - for raw sockets, the local address field
  159.  *                   contains a usable address.
  160.  *    SOCK_HAVE_BOUND_ADDR     - An address has been bound to the socket
  161.  *                   with a bind operation. This flag is used
  162.  *                   to prevent mutiple bind operations on the
  163.  *                   same socket.
  164.  */
  165.  
  166. #define SOCK_STOP_RECV            0x01
  167. #define SOCK_STOP_SEND            0x02
  168. #define SOCK_URGENT_DATA_NEXT        0x04
  169. #define SOCK_RAW_HAVE_LOCAL_ADDR    0x08
  170. #define    SOCK_HAVE_BOUND_ADDR        0x10
  171.  
  172.  
  173. /*
  174.  * SOCK_MAX_LINGER_TIME    - linger at most 2 minutes.
  175.  */
  176. #define    SOCK_MAX_LINGER_TIME    120
  177.  
  178. /*
  179.  * Information about a socket that must be kept for each process using the
  180.  * socket.
  181.  */
  182. typedef struct Sock_PrivInfo {
  183.     List_Links        links;        /* Used to attach this element to the
  184.                      * socket's clientList. */
  185.     Sock_SharedInfo    *sharePtr;    /* Common socket info. */
  186. #ifndef KERNEL
  187.     int            streamID;    /* Pdev stream ID. */
  188. #else
  189.     struct FsSocketIOHandle    *sockHandlePtr;    /* Back pointer to FS handle */
  190. #endif
  191.     int            fsFlags;    /* Flags from Fs_Open. */
  192.     Proc_PID        pid;        /* Process using this socket. */
  193.     int            hostID;        /* Host where process is based. */
  194.     int            userID;        /* User-ID of the process. */
  195.     int            clientID;    /* Client ID for the pdev.  */
  196.     int            recvFlags;    /* Flags from IOC_NET_RECV_FLAGS ioctl.
  197.                      * Needed to emulate recv, recvfrom,
  198.                      * recvmsg. Defined in <dev/net.h>. */
  199.     Net_InetSocketAddr    recvFrom;    /* Source of the packet that was just
  200.                      * read. Needed for recvfrom, recvmsg
  201.                      * emulation. */
  202.     Net_SendInfo    sendInfo;    /* Info from IOC_NET_SEND_INFO ioctl.
  203.                      * Needed to emulate send,sendto,
  204.                      * sendmsg. */
  205.     Boolean        sendInfoValid;    /* If TRUE, the sendInfo is useful. */
  206. } Sock_PrivInfo;
  207.  
  208.  
  209. #endif /* _IPS_SOCKINT */
  210.